<?php 
defined('IN_TS') or die('Access Denied.');

$studyid = intval($_GET['studyid']);

//课程信息
$strStudy = $new['study']->getOneStudy($studyid);

$strStudy['user'] = aac('user')->getOneUser($strStudy['userid']);


/////////////////分类导航开始/////////////////
//一级分类信息
$oneCate = $new['study']->find('study_cates',array(
	'cateid'=>$strStudy['cateid'],
));
//二级分类列表
$arrTwoCate = $new['study']->findAll('study_cates',array(
	'recateid'=>$oneCate['cateid'],
));
/////////////////分类导航结束/////////////////



//获取小组的分类
$strStudy['onecate'] = $new['study']->find('study_cates',array(
	'cateid'=>$strStudy['recateid'],
));
$strStudy['twocate'] = $new['study']->find('study_cates',array(
	'cateid'=>$strStudy['cateid'],
));




if($TS_USER['userid']){
	$userid = $TS_USER['userid'];
	//用户是否喜欢该课程
	$userIsLove = $new['study']->findCount('study_love',array(
		'userid'=>$userid,
		'studyid'=>$studyid,
	));

}


//判断用户学习状态,未学习为空，学习了获取学习信息
$strStudy['learn'] = '';
if(intval($TS_USER['userid'])){
	//用户学习状态
	$strStudy['learn'] = $new['study']->find('study_learn',array(
		'userid'=>intval($TS_USER['userid']),
		'studyid'=>$strStudy['studyid'],
	));
	//用户已经学课时
	$arrLessonUsers = $new['study']->findAll('study_lesson_user',array(
		'userid'=>intval($TS_USER['userid']),
		'studyid'=>$studyid,
	));
	
	foreach($arrLessonUsers as $key=>$item){
		$arrIsLearn[$item['lessonid']] = 1;//已学课时
	}
	
}


//课程下课时列表
$arrLesson = $new['study']->findAll('study_lesson',array(
	'studyid'=>$studyid,
),'orderid asc');


//课程下的全部学员

$page = isset ( $_GET ['page'] ) ? intval ( $_GET ['page'] ) : 1;
$url = tsUrl ( 'study', 'user', array ('studyid'=>$strStudy['studyid'],'page' =>'') );
$lstart = $page * 48 - 48;
 
$arrLearnUsers = $new['study']->findAll('study_learn',array(
	'studyid'=>$studyid,
),'addtime desc',null,$lstart.',48');

$userNum = $new ['study']->findCount ( 'study_learn', array (
	'studyid'=>$studyid,
) );
$pageUrl = pagination ( $userNum, 48, $page, $url );

foreach($arrLearnUsers as $key=>$item){
	$arrLearnUser[] = aac('user')->getOneUser($item['userid']);
}


$title = $strStudy['studyname'].'全部学员';
include template('user');